import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';

import format from '@dfeidao/atom-web/dt/format';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';


import p001 from './p001';
import p002 from './p002';
import p003 from './p003';

interface Par extends Event {
	page_no: number;
}
export default async function a002(fd: IFeidaoAiBrowserComponent, e: Par) {
	// todo
	// 搜索

	const project_name1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="word_title"]');
	const projectname = project_name1.value;

	const res = await nodejs<{ project_name: Array<{ completion_time: number }>, t: number }>('knowledge-base/zj-000001/s002', {
		filter: {
			project_name: projectname,
			pn: e.page_no
		}
	});
	const re = res.project_name.map((n) => {
		return { ...n, completion_time: format(n.completion_time, 2) };
	});
	const dtsj = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p001"]');
	const dtmb = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p002"]');
	const dtfy = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="p003"]');
	if (res.project_name.length > 0) {
		render(fd, re, p001, 'p001', 'inner');
		if (res.t > 20) {
			render(fd, res.t, p003, 'p003', 'inner');
		}
		dtsj.style.display = 'block';
		dtfy.style.display = 'block';
		dtmb.style.display = 'none';
	} else {
		render(fd, '', p002, 'p002', 'inner');
		dtsj.style.display = 'none';
		dtfy.style.display = 'none';
		dtmb.style.display = 'block';
	}


}
